#ifndef CVECTOR2_H
#define CVECTOR2_H

/* Copyright (C) 2011 Riccardo Marson

   This file is part of OpenPool, an open-source game of pool.

   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included
   in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
   RICCARDO MARSON BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
   AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

  See Readme.rtf for further information.

*/

#include <iostream>


//! \brief 2D vector. Mainly intended to represent pixels or GUI elements.
class CVector2
{
public:

    CVector2(); //! empty constructor
    CVector2(float x, float y); //! constructor. vector components are initialised with x, y, z
    CVector2(float components[2]); //! constructor. takes a pointer to float. nice to have when initialising vectors from rows of CMatrix4x4
    CVector2(const CVector2 &source); //! copy constructor
    ~CVector2(); //! deconstructor

    float& operator() (const unsigned short i);//! outputs mData[i]. i must be between 0 and 2
    CVector2 operator+ (CVector2 vector); //! sum of 2 vectors
    CVector2 operator+ (const float scalar); //! sum of vector and scalar constant
    CVector2 operator- (CVector2 vector); //! subtraction of 2 vectors
    CVector2 operator- (const float scalar); //! subtraction of scalar constant
    CVector2 operator* (CVector2 vector); //! element-wise multiplication
    CVector2 operator* (const float scalar); //! multiplication by a scalar value
    float Dot(CVector2 vector); //! scalar (dot) product.
    CVector2 Cross(CVector2 vector); //! vector (cross) product
    CVector2& operator= (CVector2 vector); //! assignement
    bool operator== (CVector2 vector);//! equality test
    bool operator!= (CVector2 vector); //! not equal test

    inline float GetLength(); //! returns the vector magnitude
	CVector2 Normalize();
    void SetComponents(float x, float y); //! sets (or re-sets) the vector components to x, y
    float* GetComponents(); //! provides in output the pointer to mData
    float& x(); //! returns mData[0]
    float& y(); //! returns mData[1]

    static CVector2 Rotate(float angle, CVector2& vecIn); //! returns a vector equivalent to RotZ * vecIn

    friend std::ostream & operator << (std::ostream &out, CVector2 &vec);
    
private:

    float mData[2];
};


#endif // CVECTOR2_H
